/* GUI CONVERTED from reclosea.p (converter v1.76) Wed May 22 11:22:33 2002 */
/* reclosea.p - REPETITIVE - TRANSFER WIP TO NEW ORDER                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.11.3.18 $                                                     */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 11/08/94   BY: WUG *GN98*                */
/* REVISION: 7.3      LAST MODIFIED: 03/03/95   BY: WUG *G0GJ*                */
/* REVISION: 7.3      LAST MODIFIED: 03/10/95   BY: WUG *G0GX*                */
/* REVISION: 7.3      LAST MODIFIED: 03/31/95   BY: WUG *G0K0*                */
/* REVISION: 7.3      LAST MODIFIED: 10/16/95   BY: STR *G0Y1*                */
/* REVISION: 8.5      LAST MODIFIED: 12/10/95   BY: sxb *J053*                */
/* REVISION: 8.5      LAST MODIFIED: 03/13/96   BY: jym *G1GD*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 08/04/99   BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/04/99   BY: *N050* Steve Nugent       */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 05/03/00   BY: *N09M* Inna Lyubarsky     */
/* REVISION: 9.1      LAST MODIFIED: 07/12/00   BY: *N0FD* Jean Miller        */
/* REVISION: 9.1      LAST MODIFIED: 07/12/00   BY: *N0DR* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* REVISION: 9.1      LAST MODIFIED: 12/01/00   BY: *L0P5* Sathish Kumar      */
/* Revision: 1.11.3.16     BY: Niranjan R.       DATE: 07/13/01  ECO: *P00L*  */
/* Revision: 1.11.3.17     BY: Mark Christian    DATE: 10/05/01  ECO: *N13H*  */
/* $Revision: 1.11.3.18 $  BY: Jean Miller       DATE: 05/15/02  ECO: *P05V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*V8:ConvertMode=Report                                                       */

/* CUM WORKORDER ACCTG CLOSE/WIP TRANSFER SUBPROGRAM                          */
/* TRANSFER WIP TO NEW ORDER                                                  */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter old_wo_lot as character.
define input parameter xfer_wo_lot as character.
define input parameter eff_date as date.

define shared workfile work_op_recids no-undo
   field work_op_recid as recid.

define buffer xfer_wo_mstr for wo_mstr.
define buffer xfer_wr_route for wr_route.
define buffer xfer_iro_det for iro_det.
define buffer wr_route2 for wr_route.

define new shared variable warn_ct as integer.
define new shared variable op_recno as recid.
define new shared variable opgltype like opgl_type.
define new shared variable ref like glt_ref.
define new shared variable sf_cr_acct like dpt_lbr_acct.
define new shared variable sf_cr_sub like dpt_lbr_sub.
define new shared variable sf_cr_cc like dpt_lbr_cc.
define new shared variable sf_dr_acct like dpt_lbr_acct.
define new shared variable sf_dr_sub like dpt_lbr_sub.
define new shared variable sf_dr_cc like dpt_lbr_cc.
define new shared variable sf_entity like en_entity.
define new shared variable sf_gl_amt like tr_gl_amt.

define shared variable h_wiplottrace_procs as handle no-undo.
define shared variable h_wiplottrace_funcs as handle no-undo.

define variable dept as character.
define variable emp as character.
define variable mthd_chg_var like tr_gl_amt
   column-label "Method Change!Variance".
define variable clear_acct as character.
define variable clear_sub as character.
define variable clear_cc as character.
define variable op_cost like iro_cost_tot.
define variable prev_op_cost like iro_cost_tot.
define variable qty_inque like wr_qty_inque.
define variable qty_outque like wr_qty_outque.
define variable qty_rejque like wr_qty_rejque.
define variable shift as character.
define variable trans_type as character.
define variable wip_qty_value like glt_amt column-label "Extended Cost".
define variable tempstr as character no-undo.
define variable xfer_prev_milestone_op as integer no-undo.
define variable xfer_op_cost like iro_cost_tot.
define variable xfer_prev_op_cost like iro_cost_tot
   column-label "Prev Op!Cost Total".
define variable xfer_wip_acct as character.
define variable xfer_wip_sub as character.
define variable xfer_wip_cc as character.
define variable xfer_wip_qty_value like tr_gl_amt column-label "Extended Cost".
define variable glx_set like cs_set.
define variable glx_mthd like cs_method.
define variable cur_set like cs_set.
define variable cur_mthd like cs_method.
define variable lbr_xfer like wr_lbr_totx.
define variable bdn_xfer like wr_bdn_totx.
define variable sub_xfer like wr_sub_totx.
define variable mtl_xfer like wr_mtl_totx.
define variable to_op like wr_op.
define variable gl_cost_set as character.
define variable wip_qty as decimal.
define variable wip_gl_amt as decimal.
define variable ophist_recid as recid.
define variable ok_to_transfer as logical.
define variable msg-text as character format "x(64)" extent 3 no-undo.

define variable unavgd_lbr_ll as decimal.
define variable unavgd_bdn_ll as decimal.
define variable unavgd_sub_ll as decimal.
define variable unavgd_mtl_ll as decimal.
define variable unavgd_lbr_tl as decimal.
define variable unavgd_bdn_tl as decimal.
define variable unavgd_sub_tl as decimal.
define variable unavgd_mtl_tl as decimal.
define variable unavgd_tot like wr_mtl_tot column-label "Unavgd!WIP Value".

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

define temp-table wiplot_operations no-undo
   field operation like wr_op
   field work_center like wr_wkctr
   field machine like wr_mch.

find wo_mstr where wo_lot = old_wo_lot exclusive-lock.
find first gl_ctrl no-lock.

find si_mstr where si_site = wo_site no-lock.
sf_entity = si_entity.

/*DETERMINE COSTING METHOD*/
{gprun.i ""csavg01.p""
   "(input wo_part, input wo_site,
     output glx_set, output glx_mthd, output cur_set, output cur_mthd)" }

if glx_mthd = "avg" then
   gl_cost_set = "cumorderavg".
else
   gl_cost_set = "cumorder".

/*GET DEFAULT CLEARING ACCOUNT*/
assign
   clear_acct = ""
   clear_sub = ""
   clear_cc = "".

for first rpc_ctrl
   fields(rpc_wxfer_acct rpc_wxfer_sub rpc_wxfer_cc)
no-lock: end.

if available rpc_ctrl and rpc_wxfer_acct <> "" then
   assign
      clear_acct = rpc_wxfer_acct
      clear_sub = rpc_wxfer_sub
      clear_cc = rpc_wxfer_cc.
else do:
   find first icc_ctrl no-lock no-error.
   if available icc_ctrl and icc_xclr_acct > "" then
   assign
      clear_acct = icc_xclr_acct
      clear_sub = icc_xclr_sub
      clear_cc = icc_xclr_cc.
end. /* NOT AVAIL rpc_ctrl */

find pt_mstr where pt_part = wo_part no-lock.
find pl_mstr where pl_prod_line = pt_prod_line no-lock.

if clear_acct = "" then do:

   if pl_wvar_acct > "" then do:
      {gprun.i ""glactdft.p""
         "(input ""WO_WVAR_ACCT"",
           input pt_prod_line,
           input wo_site,
           input """",
           input """",
           input no,
           output clear_acct,
           output clear_sub,
           output clear_cc)"}
   end.  /* IF PL_WVAR_ACCT */
   else
      assign
         clear_acct = gl_wvar_acct
         clear_sub = gl_wvar_sub
         clear_cc = gl_wvar_cc.

end. /* clear_acct = "" */

/*GET NEW ORDER WIP ACCOUNT*/
find xfer_wo_mstr where xfer_wo_mstr.wo_lot = xfer_wo_lot
exclusive-lock.

assign
   xfer_wip_acct = xfer_wo_mstr.wo_acct
   xfer_wip_sub = xfer_wo_mstr.wo_sub
   xfer_wip_cc = xfer_wo_mstr.wo_cc.

for each wr_route no-lock
   where wr_lot = old_wo_lot
break by wr_op:

   /*GET OPERATION COST*/
   find iro_det where iro_part = wo_mstr.wo_part
      and iro_site = wo_mstr.wo_site
      and iro_cost_set = gl_cost_set
      and iro_routing = wr_route.wr_lot
      and iro_op = wr_route.wr_op
   no-lock.

   op_cost = iro_cost_tot.

   /*SEE IF OK TO TRANSFER WIP TO NEW ORDER OP*/
   ok_to_transfer = yes.

   do for xfer_wr_route:

      find xfer_wr_route where wr_lot = xfer_wo_lot
         and wr_op = wr_route.wr_op
      no-lock no-error.

      if not available xfer_wr_route then do:

         /* WARNING: UNABLE TO TRANSFER OPERATION */
         {pxmsg.i &MSGNUM=8456 &ERRORLEVEL=2
                  &MSGARG1=wr_route.wr_op
                  &MSGBUFFER=msg-text[1]}

         /* OPERATION DOES NOT EXIST IN NEW CUM ORDER */
         {pxmsg.i &MSGNUM=4571 &ERRORLEVEL=1
                  &MSGBUFFER=msg-text[2]}

         put
            msg-text[1]
            msg-text[2]
            skip.

         warn_ct = warn_ct + 1.
         ok_to_transfer = no.

      end.

   end. /* do for xfer_wr_route */

   /* FOR ALL BUT THE FIRST OP, WE SEE IF THE CORRESPONDING OP OF
      THE NEW ORDER IS THE FIRST OP OF THAT ORDER.  IF IT IS, THEN any
      INPUT QUEUE THAT WOULD BE TRANSFERRED WOULD BE MEANINGLESS. IN
      THIS CASE THE WIP FOR THIS OP IS NOT TRANSFERRED.  */
   if not first(wr_op) then do for xfer_wr_route:

      find last xfer_wr_route
         where wr_lot = xfer_wo_lot and wr_op < wr_route.wr_op
      no-lock no-error.

      if not available xfer_wr_route then do:

         /* WARNING: UNABLE TO TRANSFER OPERATION */
         {pxmsg.i &MSGNUM=8456 &ERRORLEVEL=2
                  &MSGARG1=wr_route.wr_op
                  &MSGBUFFER=msg-text[1]}

         /* OPERATION IS THE FIRST IN NEW CUM ORDER */
         {pxmsg.i &MSGNUM=4572 &ERRORLEVEL=1
                  &MSGBUFFER=msg-text[3]}

         put
            msg-text[1]
            msg-text[3]
            skip.

         warn_ct = warn_ct + 1.
         ok_to_transfer = no.
      end.
   end.

   if ok_to_transfer
      and is_wiplottrace_enabled()
      and wr_route.wr_milestone
   then do for xfer_wr_route:

      for first xfer_wr_route
         where wr_lot = xfer_wo_lot and wr_op = wr_route.wr_op
      no-lock: end.

      if not xfer_wr_route.wr_milestone
      then do:

         /*DON'T ALLOW TRANSFER IF TO OPERATION IS A NONMILESTONE*/
         {pxmsg.i &MSGNUM=8456 &ERRORLEVEL=2 &MSGARG1=wr_route.wr_op}
         {pxmsg.i &MSGNUM=8457 &ERRORLEVEL=1}

         warn_ct = warn_ct + 1.
         ok_to_transfer = false.
      end.

      if ok_to_transfer
         and can-find(first wr_route2
                      where wr_route2.wr_lot = wr_route.wr_lot
                        and wr_route2.wr_op < wr_route.wr_op
                        and wr_route2.wr_milestone)
         and not can-find(first wr_route2
                          where wr_route2.wr_lot = xfer_wr_route.wr_lot
                            and wr_route2.wr_op < xfer_wr_route.wr_op
                            and wr_route2.wr_milestone)
      then do:

         /* DON'T ALLOW TRANSFER IF FROM OPERATION
            IS NOT FIRST MILESTONE BUT TO OPERATION IS*/
         {pxmsg.i &MSGNUM=8456 &ERRORLEVEL=2 &MSGARG1=wr_route.wr_op}
         {pxmsg.i &MSGNUM=8458 &ERRORLEVEL=1}

         warn_ct = warn_ct + 1.
         ok_to_transfer = false.
      end.

      if ok_to_transfer then do:

         /* DON'T ALLOW TRANSFER IF THERE ARE ANY INPUT QUEUE
            LOT/SERIALS THAT WERE PRODUCED BY AN OPERATION IN
            THE FROM CUMWO THAT DOES NOT EXIST IN THE TO CUMWO.
            THIS CAN HAPPEN WHEN AN OPERATION IS DELETED FROM
            THE ROUTING.*/

         xfer_prev_milestone_op =
            prev_milestone_operation
               (xfer_wr_route.wr_lot, xfer_wr_route.wr_op).

         if xfer_prev_milestone_op <> ? then do:

            for each wld_det no-lock
               where wld_alloc_id = wr_route.wr_lot
                 and wld_alloc_op = wr_route.wr_op
                 and wld_alloc_que = INPUT_QUEUE
                 and wld_prodby_op <> xfer_prev_milestone_op:

               /*UNABLE TO TRANSFER OPERATION*/
               {pxmsg.i &MSGNUM=8456 &ERRORLEVEL=2 &MSGARG1=wr_route.wr_op}

               tempstr = wld_lotser + ' ' + wld_ref + ' ' +
                         string(wld_prodby_op).

               /* INPUT QUEUE LOT/SERIAL PRODUCED BY OPERATION
                  NOT IN NEW ROUTING*/
               {pxmsg.i &MSGNUM=4107 &ERRORLEVEL=2 &MSGARG1=tempstr}

               warn_ct = warn_ct + 1.
               ok_to_transfer = false.

            end.

         end. /* if xfer_prev_milestone_op <> ? */

      end. /* if okay to transfer */

   end.

   if ok_to_transfer then do:

      /*REMEMBER QUEUE QTIES FROM "FROM" OP RECORD*/
      assign
         qty_inque = wr_qty_inque
         qty_outque = wr_qty_outque
         qty_rejque = wr_qty_rejque.

      /*INQUEUE QTY OF 1ST OP IS MEANINGLESS; DON'T TRANSFER IT*/
      if first(wr_op) then qty_inque = 0.

      /*REMEMBER UNAVERAGED VALUES (USED FOR AVG COSTING)*/
      unavgd_lbr_ll = wr_lbr_ll_act - wr_lbr_ll_totx.
      unavgd_bdn_ll = wr_bdn_ll_act - wr_bdn_ll_totx.
      unavgd_sub_ll = wr_sub_ll_act - wr_sub_ll_totx.
      unavgd_mtl_ll = wr_mtl_ll_act - wr_mtl_ll_totx.

      unavgd_lbr_tl = wr_lbr_act - wr_lbr_totx.
      unavgd_bdn_tl = wr_bdn_act - wr_bdn_totx.
      unavgd_sub_tl = wr_sub_act - wr_sub_totx.
      unavgd_mtl_tl = wr_mtl_act - wr_mtl_totx.

      unavgd_tot =
         unavgd_lbr_ll + unavgd_bdn_ll + unavgd_sub_ll + unavgd_mtl_ll +
         unavgd_lbr_tl + unavgd_bdn_tl + unavgd_sub_tl + unavgd_mtl_tl.

      /* ROUND TRANSFERRED COST TO BASE CURRENCY PRECISION */
      /* NOTE: THE ABOVE ADDED AMOUNTS ARE NOT NORMALLY ROUNDED */
      {gprun.i ""gpcurrnd.p""
         "(input-output unavgd_tot, input gl_rnd_mthd)"}

      do for xfer_wr_route:

         /*ADD QUANTITIES TO NEW ORDER OP RECORD*/
         find xfer_wr_route where wr_lot = xfer_wo_lot
            and wr_op = wr_route.wr_op
         exclusive-lock.

         assign
            wr_qty_inqueb = wr_qty_inqueb + qty_inque
            wr_qty_outqueb = wr_qty_outqueb + qty_outque
            wr_qty_rejqueb = wr_qty_rejqueb + qty_rejque
            wr_qty_inque = wr_qty_inque + qty_inque
            wr_qty_outque = wr_qty_outque + qty_outque
            wr_qty_rejque = wr_qty_rejque + qty_rejque.

         /*CREATE OP_HIST RECORD*/
         dept = "".

         find wc_mstr where wc_wkctr = xfer_wr_route.wr_wkctr
            and wc_mch = xfer_wr_route.wr_mch
         no-lock no-error.

         if available wc_mstr then dept = wc_dept.

         trans_type = "TRANSFER".

         {gprun.i ""reophist.p""
            "(input trans_type,
              input xfer_wr_route.wr_lot,
              input xfer_wr_route.wr_op,
              input emp,
              input xfer_wr_route.wr_wkctr,
              input xfer_wr_route.wr_mch,
              input dept,
              input shift,
              input eff_date,
              output ophist_recid)"}

         /*REMEMBER OP_HIST RECID FOR LATER REPORTING*/
         create work_op_recids.
         work_op_recid = ophist_recid.

         /*CALCULATE WIP G/L AMOUNT TO TAKE BACK OUT OF CLEARING*/
         if glx_mthd = "AVG" then do:
            wip_gl_amt = unavgd_tot.
         end.

         else do:

            /*GET PREV OP RECORD OF NEW ORDER TO PICK UP THE PREV OP COST*/
            xfer_prev_op_cost = 0.

            find last xfer_wr_route
               where xfer_wr_route.wr_lot = xfer_wo_lot
                 and xfer_wr_route.wr_op < wr_route.wr_op
            no-lock no-error.

            if available xfer_wr_route then do:

               find iro_det where iro_part = xfer_wo_mstr.wo_part
                  and iro_site = xfer_wo_mstr.wo_site
                  and iro_cost_set = gl_cost_set
                  and iro_routing = xfer_wr_route.wr_lot
                  and iro_op = xfer_wr_route.wr_op
               no-lock.

               xfer_prev_op_cost = iro_cost_tot.

            end.

            find xfer_wr_route where wr_lot = xfer_wo_lot
               and wr_op = wr_route.wr_op
            exclusive-lock no-error.

            find iro_det where iro_part = xfer_wo_mstr.wo_part
               and iro_site = xfer_wo_mstr.wo_site
               and iro_cost_set = gl_cost_set
               and iro_routing = xfer_wr_route.wr_lot
               and iro_op = xfer_wr_route.wr_op
            no-lock.

            xfer_op_cost = iro_cost_tot.

            xfer_wip_qty_value = qty_inque * xfer_prev_op_cost +
                                 qty_outque * xfer_op_cost +
                                 qty_rejque * xfer_op_cost.

            /* ROUND TRANSFERRED COST TO BASE CURRENCY PRECISION */
            {gprun.i ""gpcurrnd.p""
               "(input-output xfer_wip_qty_value,
                 input gl_rnd_mthd)"}

            wip_gl_amt = xfer_wip_qty_value.

         end.

         /*POST TO G/L*/
         assign
            sf_dr_acct = xfer_wip_acct
            sf_dr_sub = xfer_wip_sub
            sf_dr_cc = xfer_wip_cc
            sf_cr_acct = clear_acct
            sf_cr_sub = clear_sub
            sf_cr_cc = clear_cc
            sf_gl_amt = wip_gl_amt
            opgltype = trans_type + "-WIP"
            op_recno = ophist_recid.

         {gprun.i ""sfopgl.p""}

         /*ADD UNAVERAGED WIP VALUES TO NEW ORDER*/
         wr_lbr_ll_act = wr_lbr_ll_act + unavgd_lbr_ll.
         wr_bdn_ll_act = wr_bdn_ll_act + unavgd_bdn_ll.
         wr_sub_ll_act = wr_sub_ll_act + unavgd_sub_ll.
         wr_mtl_ll_act = wr_mtl_ll_act + unavgd_mtl_ll.

         wr_lbr_act = wr_lbr_act + unavgd_lbr_tl.
         wr_bdn_act = wr_bdn_act + unavgd_bdn_tl.
         wr_sub_act = wr_sub_act + unavgd_sub_tl.
         wr_mtl_act = wr_mtl_act + unavgd_mtl_tl.

         /*ADD G/L WIP VALUE TO NEW ORDER*/
         xfer_wo_mstr.wo_wip_tot = xfer_wo_mstr.wo_wip_tot + wip_gl_amt.

         if glx_mthd <> "AVG" then do:

            /* POST DIFFERENCE BETWEEN THE VALUE OF WIP IN THE OLD VS.
               NEW ORDERS TO METHOD CHANGE VARIANCE*/
            wip_qty_value = qty_inque * prev_op_cost +
                            qty_outque * op_cost +
                            qty_rejque * op_cost.

            /* ROUND TRANSFERRED COST TO BASE CURRENCY PRECISION */
            {gprun.i ""gpcurrnd.p""
               "(input-output wip_qty_value,
                 input gl_rnd_mthd)"}

            assign
               mthd_chg_var = wip_qty_value - xfer_wip_qty_value
               sf_cr_acct = clear_acct
               sf_cr_sub = clear_sub
               sf_cr_cc = clear_cc
               sf_gl_amt = mthd_chg_var.

            {gprun.i ""glactdft.p"" "(input ""WO_WVAR_ACCT"",
                                      input pl_prod_line,
                                      input xfer_wo_mstr.wo_site,
                                      input """",
                                      input """",
                                      input no,
                                      output sf_dr_acct,
                                      output sf_dr_sub,
                                      output sf_dr_cc)"}

            opgltype = trans_type + "-MCV".
            op_recno = ophist_recid.
            {gprun.i ""sfopgl.p""}

         end.

         FORM /*GUI*/ 
            wr_op
            qty_inque
            xfer_prev_op_cost
            qty_outque
            qty_rejque
            xfer_op_cost
            mthd_chg_var
            sf_gl_amt
         with STREAM-IO /*GUI*/  width 132 down
         title color normal
         getFrameTitle("WIP_TRANSFERRED_TO_NEW_ORDER", 30) + " " + xfer_wo_lot
         frame b.

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame b:handle).

         sf_gl_amt = wip_gl_amt.

         display
            wr_op
            qty_inque          when (not first(wr_route.wr_op))
            xfer_prev_op_cost  when (glx_mthd <> "AVG" and
                                     not first(wr_route.wr_op))
            qty_outque
            qty_rejque
            xfer_op_cost       when (glx_mthd <> "AVG")
            mthd_chg_var       when (glx_mthd <> "AVG")
            sf_gl_amt
         with frame b STREAM-IO /*GUI*/ .

         accumulate mthd_chg_var(total).
         accumulate sf_gl_amt(total).

         create wiplot_operations.
         assign
            operation = wr_op
            work_center = xfer_wr_route.wr_wkctr
            machine = xfer_wr_route.wr_mch.

      end.

   end.

   if last(wr_op)
   then do:

      underline
         mthd_chg_var    when (glx_mthd <> "AVG")
         sf_gl_amt
      with frame b.

      display
         accum total mthd_chg_var when (glx_mthd <> "AVG") @ mthd_chg_var
         accum total sf_gl_amt @ sf_gl_amt
      with frame b STREAM-IO /*GUI*/ .

   end. /* IF LAST(wr_op) */

   prev_op_cost = op_cost.

end.

if is_wiplottrace_enabled() then do:
   run transfer_operation_lots_to_new_id
      (old_wo_lot,
       table wiplot_operations,
       xfer_wo_lot,
       emp,
       dept,
       shift,
       eff_date).
end.

PROCEDURE transfer_operation_lots_to_new_id:
   define input parameter ip_from_wo_id as character no-undo.
   define input parameter table for wiplot_operations.
   define input parameter ip_to_wo_id as character no-undo.
   define input parameter ip_emp like op_emp no-undo.
   define input parameter ip_dept like wc_dept no-undo.
   define input parameter ip_shift like op_shift no-undo.
   define input parameter ip_effdate as date no-undo.

   define variable ophist_recid as recid no-undo.
   define variable transtype as character no-undo initial 'TRANSFER'.

   if not transaction then
      run tell_user_trans_not_active in h_wiplottrace_procs.

   for first wo_mstr where wo_lot = ip_from_wo_id
   no-lock: end.

   for each wiplot_operations no-lock:

      for each wld_det exclusive-lock
         where wld_alloc_id = ip_from_wo_id
           and wld_alloc_op = operation:

         {gprun.i ""reophist.p""
            "(input transtype,
              input ip_from_wo_id,
              input operation,
              input ip_emp,
              input work_center,
              input machine,
              input ip_dept,
              input ip_shift,
              input ip_effdate,
              output ophist_recid)"}

         for first op_hist where recid(op_hist) = ophist_recid
         exclusive-lock: end.

         assign
            op_wip_lotser = wld_lotser
            op_wip_ref = wld_ref.

         /*REGISTER THE MATERIAL TRANSFERRED OUT IN THE TRACING JOURNAL*/
         run add_trace_record in h_wiplottrace_procs
            (input OPERATION_HISTORY,
             input op_trnbr,
             input CONSUMED_MTL,
             input WIP_MTL,
             input wld_prodby_id,
             input wld_prodby_op,
             input wo_part,
             input wld_lotser,
             input '',
             input wld_qty_oh).

         /*UPDATE THE WIP LOT MASTER*/
         run update_wip_lot_master_record in h_wiplottrace_procs
            (input wld_prodby_id,
             input wld_prodby_op,
             input wld_lotser,
             input CUM_TRANS_OUT,
             input wld_qty_oh).

         /*REGISTER THE MATERIAL TRANSFERRED IN IN THE TRACING JOURNAL*/
         run add_trace_record in h_wiplottrace_procs
            (input OPERATION_HISTORY,
             input op_trnbr,
             input PRODUCED_MTL,
             input WIP_MTL,
             input ip_to_wo_id,
             input wld_prodby_op,
             input wo_part,
             input wld_lotser,
             input '',
             input wld_qty_oh).

         /*UPDATE THE WIP LOT MASTER*/
         run update_wip_lot_master_record in h_wiplottrace_procs
            (input ip_to_wo_id,
             input wld_prodby_op,
             input wld_lotser,
             input CUM_TRANS_IN,
             input wld_qty_oh).

         /*ASSIGN THE WIP LOT INVENTORY DETAIL RECORD TO THE NEW CUM ORDER*/
         assign
            wld_alloc_id = ip_to_wo_id
            wld_prodby_id = ip_to_wo_id.

         do with frame c:

            /* SET EXTERNAL LABELS */
            setFrameLabels(frame c:handle).

            display
               operation
               language_mnemonic('wld_det', 'wld_alloc_que', wld_alloc_que)
                  @ wld_alloc_que
               wld_lotser
               op_wip_ref column-label "Reference"
               wld_qty_oh
            with title color normal
            (getFrameTitle("WIP_LOT/SERIALS_TRNSFRD_TO_NEW_ORD",55))
            with frame c STREAM-IO /*GUI*/ .

         end. /* do with frame c */

      end. /* for each wld_det */

   end. /* for each wiplot_operations */

END PROCEDURE.
